

function ListNode(name) {
    this.name = name;
    this.next = null;
}

function reverseListMN(head, m, n) {
    let dummy = new ListNode(0)
    dummy.next = head
    for (let i = 0; i < m - 1; i++) { // -1 是保证目标前一个
        dummy = dummy.next
    }

    let pre = dummy;
    let curr = dummy.next
    for (let i = 0; i < n - m; i++) {
        let next = curr.next;
        curr.next = next.next;
        next.next = curr;
        pre.next = next
    }

    return dummy.next
}


// 链表的基本机构
function ListNode(val) {
    this.name = val;
    this.next = null;  // 一般是下一个的指针 最后一个为null
}

var a = new ListNode(1);
var b = new ListNode(2);
var c = new ListNode(3);
a.next = b;
b.next = c;

let head = a;
while (head) {
    console.log("转换前", head.name);
    head = head.next
}

head = reverseListMN(a, 0, 1);

while (head) {
    console.log("转换后", head.name);
    head = head.next
}